package com.authine.cloudpivot.ext.applicationservice;

import com.alibaba.cola.dto.RequestContext;
import com.alibaba.fastjson.JSONObject;
import com.authine.cloudpivot.ext.constants.AppConst;
import com.authine.cloudpivot.ext.constants.PlatformConst;
import com.authine.cloudpivot.ext.utils.system.RoleUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName ResourceRefreshService
 * @Description: 刷新本地资源
 * @Author fj
 * @Date 2021/9/29
 * @Version V1.0
 **/
@Slf4j
public class ResourceRefreshService {
    static {
        log.info("===================Preparing to  refresh resource==================");

        // 设置登录信息，避免报错
        RequestContext.get().setCorpLoginId(PlatformConst.corpLoginId);
        RequestContext.get().setLoginId(PlatformConst.loginId);
        RequestContext.get().setLoginName(PlatformConst.loginName);
        log.info("RequestContext：{}",JSONObject.toJSONString(RequestContext.get()));
        RoleUtils.refreshResource(AppConst.COMMODITYMATERIALS);

        // 清除登录信息
        RequestContext.clear();
        log.info("===================Refresh resource succeeded==================");
    }
}
